<template>
	<view style="background-color: #fff;">
		<view class="repair">
			<view class="uni-title">补卡类型：{{applyData.hr_attend_typeCard}}</view>
		</view>
		<view class="repair">
			<view class="uni-title">补卡人：{{applyData.username}}</view>
		</view>
		<view class="repair">
			<view class="uni-title" style="width: 30%;">补卡日期：{{applyData.hr_attend_apply_data}}</view>
		</view>
		<view class="repair">
			<view class="uni-title">补卡内容：</view>
		</view>
		<view class="repair-text">
			<textarea style="height:300upx;" @input="bindTextAreaBlur" :disabled="true" :value="applyData.hr_attend_apply_reason"/>
		</view>
		<block v-if="applyData.hr_attend_status === 1">
			<view class="repair-botton">
				<button type="primary" :disabled="disabled" @tap="handleClick">同意</button>
			</view>
			<view class="repair-botton">
				<button type="warn" @tap="handleErrClick">驳回</button>
			</view>
		</block>
		<view class="repair-botton" v-if="applyData.hr_attend_status !== 1">
			<button type="warn" plain="true" disabled="true" @tap="handleErrClick">已审批</button>
		</view>
	</view>
</template>
<script>
	import {apiGetApplyData,apiExaminationAndApproval,apiRejectAttendApply} from '@/common/api.js';
	export default {
		data() {
			return {
				applyData:{
					"apply":{},
					"user":{}
				},
				apply_id:''
			}
		},
		onLoad(e) {
			uni.showLoading({
				title: '数据加载中...',
				mask: true
			});
			this.apply_id = e.apply_id
			this.getApplyData(e.apply_id)
		},
		methods: {
			handleClick(){
				uni.showLoading({
					mask: true
				});
				this.examinationAndApproval(this.apply_id)
			},			
			handleErrClick (){
				uni.showLoading({
					mask: true
				});
				apiRejectAttendApply({
					hr_attend_apply_id:this.apply_id
				}).then(res=>{
					this.toast(res.data.msg)
					setTimeout(()=>{
						uni.navigateBack({
							delta:1
						})
					},1400)
				}).catch(err=>{
					uni.hideLoading()
				})
			},
			examinationAndApproval(apply_id){
				apiExaminationAndApproval({
					hr_attend_apply_id:apply_id
				}).then(res=>{
					this.toast(res.data.msg)
					setTimeout(()=>{
						uni.navigateBack({
							delta:1
						})
					},1400)
				}).catch(err=>{
					this.toast(err.data.msg)
				})
			},
			getApplyData(apply_id){
				apiGetApplyData(apply_id).then(res=>{
					uni.hideLoading()
					this.applyData = res.data.data
				}).catch(err=>{
					uni.hideLoading()
					this.toast('数据异常，请稍后再试！')
				})
			},
			toast(title,icon='none'){
				uni.showToast({
					title: title,
					mask: true,
					icon:icon,
					duration: 1500
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.repair{
		display: flex;
		align-items:center;
		padding: 20upx 30upx;
		box-sizing:border-box;
		border-bottom: 1px solid #eee;
		&-radios{
			padding-left: 30upx;
		}
	}
	.repair-text{
		padding: 30upx;
	}
	.repair-botton{
		padding: 30upx;
		
	}
</style>
